package com.ruoyi.web.controller.system;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.base.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.page.TableDataInfo;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.base.BaseController;
import com.ruoyi.system.domain.WdyNotice;
import com.ruoyi.system.service.IWdyNoticeService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 新闻公告 信息操作处理
 * 
 * @author ruoyi
 * @date 2019-10-25
 */
@Controller
@RequestMapping("/system/wdyNotice")
public class WdyNoticeController extends BaseController
{
    private String prefix = "system/wdyNotice";
	
	@Autowired
	private IWdyNoticeService wdyNoticeService;
	
	@RequiresPermissions("system:wdyNotice:view")
	@GetMapping()
	public String wdyNotice()
	{
	    return prefix + "/wdyNotice";
	}
	
	/**
	 * 查询新闻公告列表
	 */
	@RequiresPermissions("system:wdyNotice:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(WdyNotice wdyNotice)
	{
		startPage();
        List<WdyNotice> list = wdyNoticeService.selectWdyNoticeList(wdyNotice);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出新闻公告列表
	 */
	@RequiresPermissions("system:wdyNotice:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(WdyNotice wdyNotice)
    {
    	List<WdyNotice> list = wdyNoticeService.selectWdyNoticeList(wdyNotice);
        ExcelUtil<WdyNotice> util = new ExcelUtil<WdyNotice>(WdyNotice.class);
        return util.exportExcel(list, "wdyNotice");
    }
	
	/**
	 * 新增新闻公告
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存新闻公告
	 */
	@RequiresPermissions("system:wdyNotice:add")
	@Log(title = "新闻公告", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(WdyNotice wdyNotice)
	{		
		return toAjax(wdyNoticeService.insertWdyNotice(wdyNotice));
	}

	/**
	 * 修改新闻公告
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Long id, ModelMap mmap)
	{
		WdyNotice wdyNotice = wdyNoticeService.selectWdyNoticeById(id);
		mmap.put("wdyNotice", wdyNotice);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存新闻公告
	 */
	@RequiresPermissions("system:wdyNotice:edit")
	@Log(title = "新闻公告", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(WdyNotice wdyNotice)
	{		
		return toAjax(wdyNoticeService.updateWdyNotice(wdyNotice));
	}
	
	/**
	 * 删除新闻公告
	 */
	@RequiresPermissions("system:wdyNotice:remove")
	@Log(title = "新闻公告", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(wdyNoticeService.deleteWdyNoticeByIds(ids));
	}
	
}
